package com.itheima.mapper;

import com.itheima.pojo.NameValueData;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {

    /**
     * 通过班级id查询学生
     *
     * @param id
     * @return
     */
    @Select("select * from student where clazz_id = #{id}")
    List<Student> selectStuByClazzId(Integer id);

    /**
     * 分页查询班级
     * @param page
     * @return
     */
    List<Student> selectStusList(StudentQueryParam page);

    /**
     * 添加学员
     * @param student
     */
    void insertStudent(Student student);

    /**
     * 根据id查询学生
     * @param id
     * @return
     */
    @Select("select * from student where id = ${id}")
    Student getStufentById(Integer id);

    /**
     * 修改学生信息
     * @param student
     */
    void updateStudent(Student student);

    /**
     * 批量删除学员
     * @param ids
     */
    void deleteStudents(Integer[] ids);

    /**
     * 修改学生违纪次数及扣分
     */
    @Update("update student set violation_count =  (violation_count + 1 ) ,violation_score = #{score} where id= #{id}")
    void updateStudentViolation(Integer id, Integer score);

    /**
     * 根据班级查询人数
     * @return
     */
    List<Map<String, Object>> selectStuNumByClazzId();

    /**
     * 学员学历统计
     * @return
     */
    List<NameValueData> studentDegreeData();
}
